public with sharing class AssociationController 
{
	public ContentItems contentItems {get;set;}
	
	public AssociationController()
	{
		 String referrerCode = Apexpages.currentPage().getParameters().get(LoanController.REFERRER_CODE);
		 System.debug('Referrer code =' + referrerCode);
		 if(referrerCode != null)
		 {
		 	this.contentItems = new ContentItems();
		 	System.debug('Referrer code =' + referrerCode);
		 	try
		 	{
		 		PageContent__c content = [Select id, contentArea1__c from PageContent__c where account__r.referrerCode__c = :referrerCode];
		 		this.contentItems.contentArea1 = content.contentArea1__c; 
		 		Cookie referrerCookie =  new Cookie(LoanController.REFERRER_CODE,referrerCode,null,LoanController.COOKIE_EXPIRY_SECONDS,false);
                ApexPages.currentPage().setCookies(new Cookie[]{referrerCookie});
		 	}
		 	catch(System.Exception e)
		 	{
		 		System.debug('It appears we have an error');
		 	}
		 }
	}
	
	public class ContentItems
	{
		public String contentArea1 {get;set;}
	}
	
	
	static testMethod void testThis()
	{
		RecordType recordType = [Select id From RecordType Where Name = 'Franchisee'];
        Account account = new Account(recordtypeid=recordType.id);
        account.friendlyUrl__c = 'test';
        account.name = 'Giles';
        Database.insert(account);
        pageContent__c pageContent = new PageContent__c();
        pageContent.account__c = account.id;
        pageContent.contentArea1__c = 'This is some content';
        Database.insert(pageContent);
		PageReference pageReference = new PageReference('/test');
		//Now we need to get the referrer code field
		Account newAccount = [Select id, referrerCode__c from Account where id = :account.id];
		pageReference.getParameters().put(LoanController.REFERRER_CODE, newAccount.referrerCode__c);
        Test.setCurrentPage(pageReference);
        AssociationController associationController = new AssociationController();
        System.assert(associationController.contentItems.contentArea1 == 'This is some content');
	}

}